<?php
class h5 extends base{

	public function init(){ // 公用
		parent::init(); // 这是必须的

		$this->tit = "订单";
		$this->current = 'main';

		$this->orderObj = D('company_order');
		$this->order_logObj = D('company_order_log');

		$this->score_logObj = D('company_score_log');
		$this->money_logObj = D('company_money_log');

		$this->areaObj = D('company_area');
		$this->cateObj = D('company_cate');
		$this->zoneObj = D('company_zone');
		$this->deviceObj = D('company_device');
		$this->adminObj = D('company_admin');

		$this->shopObj = D('company_shop');
		$this->shops = $this->shopObj->get_shop_data($this->company['id'],$this->admin_id);
		// dump($this->shops);exit;
		// $this->smsObj = D('sms');

		$this->auth_list = $this->adminObj->get_auth_list($this->admin);
		$this->areas = $this->auth_list['areas'];
		$this->cates = $this->auth_list['cates'];
		$this->zones = $this->auth_list['zones'];
		// dump($this->auth_list);exit;
		
		$this->config = $this->company_setting['baoxiu'];
	}

	public function index(){
		$this->redirect("/index_company/main/order");
	}


	public function order(){
		$this->tab = $this->tab?$this->tab:'1';
		$arrBase = array('tab' => $this->tab,'page' => '0000',);
		if($this->keyword){
			$arrBase = array_merge($arrBase,array('keyword' => $this->keyword));
		}
		$this->nextpage = url($this->routeUrl,$this->action.'_loaddata', $arrBase);

	}


	//loaddata
	public function order_loaddata(){
		
		$cond = "status=1 ".$this->cond_base;
		// 加入查询条件
		if($this->tab){
			switch($this->tab){
				case '1':
					$cond .=" and order_status=1 and hongbao>0";
					break;
				case '2':
					$cond .=" and order_status=1";
					break;
			}
		}
		//权限
		// switch($this->admin['level']){
		// 	case '0'://管理员
		// 		$cond .=" ";
		// 		break;
		// 	case '1'://报修员
		// 		$cond .=" and admin_id={$this->admin_id}";
		// 		break;
		// 	case '2'://报修组长
		// 		$cond .=" ".$this->cond_cate.$this->cond_zone;
		// 		break;
		// 	case '3'://维修师傅
		// 		$cond .=" and shifu_id={$this->admin_id}";
		// 		break;
		// 	case '4'://维修组长
		// 		$cond .=" ".$this->cond_cate.$this->cond_zone;
		// 		break;
		// }

		//搜索
		if($this->keyword){
			$cond.=" and (title like '%".$this->keyword."%' or intro like '%".$this->keyword."%' and local like '%".$this->keyword."%') ";
		}

		$result = $this->orderObj->getList($cond);
        if($result){
			$lists = $result['list'];
			
			// 
        	foreach ($lists as $val) {
				// 距离判断
				if($val['map']>0){

					$km = distance($val['shop']['lat'],$val['shop']['lat'],$this->admin['lat'],$this->admin['lat']);
					$km = round($km,4);
					$val['is_km'] = $km;
					if($val['map'] < $km){
						$val['is_no'] = 1;
					}
				}
				$list[] = $val;
			}
        	// $this->list = $list;
			// $this->showPage = $result['showPage'];
			// $this->total = $result['total'];
			
			$this->list = $list;

			$this->areas = $this->areaObj->ids($lists,'area_id');
			$this->cates = $this->cateObj->ids($lists,'cate_id');
			$this->zones = $this->zoneObj->ids($lists,'zone_id');
			$this->devices = $this->deviceObj->ids($lists,'device_id');
			$this->admins = $this->adminObj->ids($lists,'admin_id');
			$this->shifus = $this->adminObj->ids($lists,'shifu_id');
			$this->shops = $this->shopObj->ids($lists,'shop_id');
		}else{
			die('0');
		}

	}


	public function search(){
		// $this->cate = $this->cateObj->find(array("url='{$url}' and status=1"));
	}

	//详情
	public function order_detail(){
		$id = arg('id');
		$info = $this->orderObj->get_detail($id); 
		if($info){
			$this->info = $info;
			
			if($info['pj_star1']){
				for ($i=1; $i <= $info['pj_star1']; $i++) { 
					$pj_star1[$i] = 'checked';
				}
				for ($i=1; $i <= $info['pj_star2']; $i++) { 
					$pj_star2[$i] = 'checked';
				}
				$this->pj_star1 = $pj_star1;
				$this->pj_star2 = $pj_star2;
			}
		}
	}


}